<?php
/**
 * Joomla! 1.5 component JoomGPSTracks
 *
 * @version $Id: view.html.php 2009-06-24 15:40:19 svn $
 * @author Michael Pfister
 * @package joomGPStracks
 * @subpackage backend
 * @license GNU/GPL
 * @filesource
 *
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');


// Import Joomla! libraries
jimport( 'joomla.application.component.view');
/**
 *
 */
class JoomgpstracksViewCats extends JView {
    /**
     *
     * @global object $mainframe
     * @global string $option
     * @param object $tpl
     * @return
     */
    function display($tpl = null) {
        global $mainframe, $option;

        if($this->getLayout() == 'form'):
			$this->_displayForm($tpl);
            return;
		endif;

        if($this->getLayout() == 'editform'):
			$this->_displayEditcat($tpl);
            return;
		endif;

        $model =& $this->getModel();

        $order = JRequest::getVar( 'order', 'order', 'post', 'string' );

        $filter_order		= $mainframe->getUserStateFromRequest( "$option.filter_order",		'filter_order',		'ordering',	'cmd' );
        $filter_order_Dir	= $mainframe->getUserStateFromRequest( "$option.filter_order_Dir",	'filter_order_Dir',	'',			'word' );

        $lists['order']		= $filter_order;
        $lists['order_Dir']	= $filter_order_Dir;

	$rows =& $this->get( 'Data');
        $list = $model->createCatList($rows);

	$total		= & $this->get( 'Total');
        $pagination = & $this->get( 'Pagination' );

        $this->assignRef('lists',	$lists);
        $this->assignRef('pagination',	$pagination);
        $this->assignRef('list',    $list);

        parent::display($tpl);
    }

    /**
     *
     * @global object $mainframe
     * @global string $option
     * @param object $tpl
     */
    function _displayForm($tpl)  {
        global $mainframe, $option;

        $model = $this->getModel();
        $parent = $model->getParent();
        array_unshift($parent, array('id' => 0, "title" => JText::_('GPS_NOTHING')));
        $editor =& JFactory::getEditor();
        $lists['block'] 	= JHTML::_('select.booleanlist',  'publish', 'class="inputbox" size="1"', '' );
        $lists['parent'] 	= JHTML::_('select.genericlist', $parent, 'parent', 'size="1"', 'id', 'title', '');
        $config =& JoomgpstracksHelper::getConfig();
        $max_file_size = $config->max_size * 1000;

        $this->assignRef('lists',	$lists);
        $this->assignRef('editor', $editor);
        $this->assignRef('maxsize', $max_file_size);

        parent::display($tpl);
    }

    /**
     *
     * @global object $mainframe
     * @param object $tpl
     */
    function _displayEditcat($tpl)  {
        global $mainframe;

        $editor =& JFactory::getEditor();
        $model =& $this->getModel();
        $parent = $model->getParent();
        array_unshift($parent, array('id' => 0, "title" => JText::_('GPS_NOTHING')));
        $id =& JRequest::getInt( 'id');
        $data = $model->getCat($id);
        $lists['block'] 	= JHTML::_('select.booleanlist',  'publish', 'class="inputbox" size="1"', $data->published );
        $lists['parent'] 	= JHTML::_('select.genericlist', $parent, 'parent', 'size="1"', 'id', 'title', $data->parent);

        $config =& JoomgpstracksHelper::getConfig();
        $max_file_size = $config->max_size * 1000;

        $this->assignRef('lists',	$lists);
        $this->assignRef('editor', $editor);
        $this->assignRef('maxsize', $max_file_size);
        $this->assignRef('data', $data);

        parent::display($tpl);
    }
    
}
?>